﻿@model Sharp.WebBooter.Areas.CMS.Models.GatherViewModel
@{
    Layout = null;
}
<style>
    .Gather_Edit table {
        border-spacing: 3px;
        width: 98%;
    }

    .Gather_Edit .text-right {
        text-align: right;
    }

    .Gather_Edit .text-left {
        text-align: left;
    }

    .Gather_Edit #Replace, .Gather_Edit #Filter {
        width: 570px;
        height: 199px;
    }
</style>
<section class="content-header">
    <h1>
        <a data-toggle="ajaxLoad" href="@Request.Url.ToString()">采集规则编辑</a>
    </h1>
    <ol class="breadcrumb">
        <li><a href="@Url.Action("Index", "Home")"><i class="fa fa-home"></i> 首页</a></li>
        <li class="active">基础库</li>
    </ol>
</section>

<div class="content Gather_Edit">
    <div class="row">
        <div class="col-lg-12">
            <div class="box box-primary">
                <div class="box-body">
                    @using (Html.Bootstrap().BeginForm(c => c.Horizontal()))
            {
                        <fieldset>
                            <legend><strong>基本设置</strong></legend>
                            <table class="text-center">
                                <tr>
                                    <td class="text-right" style="width: 146px">
                                        任务名称：
                                    </td>
                                    <td class="text-left">
                                        @Html.Bootstrap().TextBoxFor(x => x.Name)
                                        <span class="style1">*</span>
                                    </td>
                                    <td></td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        列表开始地址：
                                    </td>
                                    <td colspan="2" class="text-left">
                                        @Html.Bootstrap().TextareaFor(x => x.StartUrl)
                                        <span class="style1">*</span>
                                    </td>
                                </tr>
                                @*<tr>
                                    <td class="text-right">
                                        下载站外图片：
                                    </td>
                                    <td colspan="2" class="text-left">
                                        <label>
                                            <input name="CanDownImg" type="radio" @(Model.CanDownImg ? "checked" : "") value="true" /> 是
                                        </label>

                                        <label>
                                            <input name="CanDownImg" type="radio" @(!Model.CanDownImg ? "checked" : "") value="false" /> 否
                                        </label>
                                        当上面选择"是",如果不下载站外图片,则保持外链别人的图片.
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        是否加水印：
                                    </td>
                                    <td colspan="2" class="text-left">
                                        <label>
                                            <input name="DrawWaterMark" type="radio" @(Model.DrawWaterMark ? "checked" : "") value="true" /> 是
                                        </label>

                                        <label>
                                            <input name="DrawWaterMark" type="radio" @(!Model.DrawWaterMark ? "checked" : "") value="false" /> 否
                                        </label>
                                    </td>
                                </tr>*@
                                <tr>
                                    <td class="text-right">
                                        采集方式：
                                    </td>
                                    <td colspan="2" class="text-left">
                                        <label>
                                            <input name="isSpider" type="radio" @(Model.IsSpider==2 ? "checked" : "") value="2" /> 浏览器爬虫
                                        </label>
                                        <label>
                                            <input name="isSpider" type="radio" @(Model.IsSpider==1 ? "checked" : "") value="1"/> 漫游蜘蛛
                                        </label>

                                        <label>
                                            <input name="isSpider" type="radio" @(Model.IsSpider ==0? "checked" : "") value="0"/> 普通采集
                                        </label>
                                    </td>
                                </tr>

                            </table>
                        </fieldset>
                        <br>
                        @*<span data-bind="text:isSpider"></span>*@
                        <fieldset id="CategoryRuleArea" data-bind="visible:!isSpider">
                            <legend><strong>栏目匹配规则</strong></legend>
                            <table class="text-center">
                                <tr>
                                    <td class="text-right" style="width: 140px">
                                        扫描栏目页范围：
                                    </td>
                                    <td class="text-left">
                                        @Html.Bootstrap().TextareaFor(x => x.CategoryArea)
                                        <a href="Rule.aspx" target="_blank"><strong>规则生成器</strong></a>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        文章页链接：
                                    </td>
                                    <td class="text-left">
                                        @Html.Bootstrap().TextareaFor(x => x.ContentPageUrl)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        栏目下一页：
                                    </td>
                                    <td class="text-left">
                                        @Html.Bootstrap().TextareaFor(x => x.CategoryPageNextUrl)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">忽略采集的URL：</td>
                                    <td class="text-left">
                                        @Html.Bootstrap().TextareaFor(x => x.IgnoreUrl)
                                        正则表达式
                                    </td>
                                </tr>

                            </table>
                        </fieldset>
                        <br>
                        <fieldset>
                            <legend><strong>文章匹配规则</strong></legend>
                            <table class="text-center">
                                <tr>
                                    <td class="text-right" style="width: 140px">
                                        标题： <span class="style1">*</span>
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.ContentTitle)

                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        内容：
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.Content)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        作者：
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.Author)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        来源：
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.ComeFrom)

                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        日期：
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.UpdateTime)

                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        文章页下一页地址：
                                    </td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.ContentPageNextUrl)
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">全文文章页地址：</td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.FullArticleUrl)

                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">内容页Url规则：</td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.ContentPageRule)

                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">爬行一下域名：</td>
                                    <td>
                                        @Html.Bootstrap().TextareaFor(x => x.SpiderDomains)

                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                        <br>
                        <fieldset>
                            <legend><strong>内容过滤与替换</strong></legend>
                            <table class="text-center">
                                <tr>
                                    <td class="text-right" style="width: 146px">
                                        <img title="每项设置用回车键分割" alt="" height="16" src="../../Images/help.gif" width="16" />过滤内容：
                                    </td>
                                    <td style="width: 600px" class="text-left">
                                        <textarea id='txt_ln' name='content' rows='10' cols='4' style='overflow: hidden; height: 200px; width: 28.8px; border-right: 0; text-align: right; background: #d0d0d0;' readonly="readonly"></textarea>

                                        @Html.Bootstrap().TextareaFor(x => x.Filter).AddClass("pull-right")
                                    </td>
                                    <td>
                                        <table style="width: 100%;">
                                            <tr>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<IFRAME[^>]*?>[\\s\\S]*?</IFRAME>')">IFRAME</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<TABLE[^>]*?>[\\s\\S]*?</TABLE>')">TABLE</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<FORM[^>]*?>[\\s\\S]*?</FORM>')">FORM</a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<OBJECT[^>]*?>[\\s\\S]*?</OBJECT>')">OBJECT</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<SCRIPT[^>]*?>[\\s\\S]*?</script>')">SCRIPT</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<STYLE[^>]*?>[\\s\\S]*?</STYLE>')">STYLE</a>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<FONT[^>]*?>[\\s\\S]*?</FONT>')">FONT</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<SPAN[^>]*?>[\\s\\S]*?</SPAN>')">SPAN</a>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0)" onclick="toDoc('Filter', '<A[^>]*?>[\\s\\S]*?</A>')">A</a>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-right">
                                        <img alt="" title="每项设置要跟上面的一一对应。" height="16" src="../../Images/help.gif" width="16" />被替换为：
                                    </td>
                                    <td class="text-left">
                                        <textarea id='txt_ln2' name='content' rows='10' cols='4' style='overflow: hidden; height: 200px; width: 28.8px; border-right: 0px; text-align: right; background: #d0d0d0; float: left'></textarea>
                                        @Html.Bootstrap().TextareaFor(x => x.Replace).AddClass("pull-right")

                                    </td>
                                    <td>
                                        &nbsp;
                                    </td>
                                </tr>
                                <tr>
                                    <td class="text-center" colspan="2" height="30"></td>
                                    <td class="text-center" height="30">
                                        &nbsp;
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                        @Html.HiddenFor(x => x.Id)
                    }
                </div>
                <div class="box-footer text-center box-outfooter">
                    @Html.Bootstrap().Button("保存").Style(BootstrapStyle.Primary).Click("window.app.saveForm(event,'" + @Url.Action("Save") + "');")
                </div>
            </div>
        </div>
    </div>
</div>
<script src="~/Areas/CMS/ViewModel/Gather/Edit.js"></script>
<script type="text/javascript">
    function $get(str) {
        return document.getElementById(str);
    }

    function show_ln(event) {
        var iadd = 1;
        var obj = event.srcElement ? event.srcElement : event.target;
        var str;
        var x;
        var i;
        if (obj === $get("Filter")) {
            x = $get("Filter").value.split('\n').length + iadd;
            str = '';
            for (i = 1; i < x; i++)
                str += i + '\n';

            $get("txt_ln").value = str;
            $get("txt_ln").scrollTop = $get("Filter").scrollTop;
        }
        if (obj === $get("Replace")) {
            x = $get("Replace").value.split('\n').length + iadd;
            str = '';
            for (i = 1; i < x; i++) {
                str += i + '\n';
            }

            $get('txt_ln2').value = str;
        }
    }

    function toDoc(cId, str) {
        $get(cId).value = $get(cId).value + str;
        return false;
    }
    function ToLineNum() {
        for (var i = 0; i < ($get("Filter").value.split('\n').length) ; i++)
            $get('txt_ln').value += (i + 1) + '\n';
        for (var i = 0; i < ($get("Replace").value.split('\n').length) ; i++)
            $get('txt_ln2').value += (i + 1) + '\n';
    }

    ToLineNum();
    $("#Filter,#Replace").keyup(function (event) { show_ln(event); });

    $('input[type="radio"]').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional
    });

    $("input[name='isSpider']").on('ifClicked', function (event) {
        //debugger
        if ($("input[name='isSpider']:checked").val() === "false") {
            $("#CategoryRuleArea").hide();
        } else {
            $("#CategoryRuleArea").show();
        }
    });
    $(function () {

        var vm = new GatherEditViewModel();
        vm.isSpider(@Model.IsSpider.ToString().ToLower());
        ko.applyBindings(vm, $(".Gather_Edit")[0]);
    });
</script>